/**
 * 
 */
package com.wgo.precise.client.ui.view.util.validators;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;

import com.wgo.precise.client.ui.controller.ModelStatus;
import com.wgo.precise.client.ui.model.ClientModelItem;
import com.wgo.precise.client.ui.model.RequirementWrapper;


/**
 * @author petterei
 *
 * @version $Id: RequirementStatusSelectionValidator.java,v 1.1 2006-03-07 14:56:23 petterei Exp $
 */

public class RequirementStatusSelectionValidator implements ISelectionStatusValidator {
	
	private ClientModelItem clientModelItem;
	
		
	public RequirementStatusSelectionValidator(ClientModelItem clientModelItem) {
		this.clientModelItem = clientModelItem;
	}


	public IStatus validate(Object[] selection) {
		for (Object object : selection) {
			if (! (object instanceof RequirementWrapper)) {
				return new ModelStatus(IStatus.ERROR, "Select only Requirements!");
			}
			if (object == clientModelItem) {
				return new ModelStatus(IStatus.ERROR, "Impossible to link a requirement to itself!");
			}
		}
		return new ModelStatus(IStatus.OK, "Selection ok.");
	}
}
